package com.snailhd.common.util.web;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 
*    
* 项目名称：paychannel2   
* 类名称：SpringContextUtil   
* 类描述：   SPRING bean获取管理器
* 创建人：何润   
* 创建时间：2016年12月19日 下午12:41:00   
* @version 1.0   
*
 */
@Component
public class SpringContextUtil implements ApplicationContextAware{
	private static ApplicationContext context;

	@Override
	@SuppressWarnings("static-access")
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
        SpringContextUtil.context = arg0;
	}
	public static Object getBean(String beanName){
		 return context.getBean(beanName);
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static <T> T getBean(String beanName,Class clazz){
		 return (T) context.getBean(beanName, clazz);
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static <T> T getBean(Class clazz){
		return (T) context.getBean(clazz);
	}
	public static ApplicationContext getContext(){
		return context;
	}

}
